package com.atguigu.srb.base.config;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Swagger2Config {
    @Bean
    public Docket adminApiConfig(){

        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("admin")
                .apiInfo(adminInfo())
                .select()//启动一个过滤器
                .paths(Predicates.and(PathSelectors.regex("/admin/.*")))//选择路径的断言，and后接上正则访问路径是/admin/的所有
                .build();

    }
    private ApiInfo adminInfo(){
     return    new ApiInfoBuilder()
                .title("后台接口文档")
                .description("各个接口的信息")
                .contact(new Contact("old cookies","www.winter.com","995794390@qq.com"))
                .build();
    }

    @Bean
    public Docket webApiConfig(){

        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("web")
                .apiInfo(webInfo())
                .select()//启动一个过滤器
                .paths(Predicates.and(PathSelectors.regex("/api/.*")))//选择路径的断言，and后接上正则访问路径是/admin/的所有
                .build();

    }
    private ApiInfo webInfo(){
        return    new ApiInfoBuilder()
                .title("客户端接口文档")
                .description("客户端各个接口的信息")
                .contact(new Contact("old cookies","www.winter.com","995794390@qq.com"))
                .build();
    }


}
